package goroutine

import (
	"fmt"
	"time"
)

func channelSelect(channel chan<- string, quit <-chan string) {
	for {
		select {
		case value := <-quit:
			fmt.Println("子线程: 收到了", value)
			return
		default:
			channel <- "催催你"
			fmt.Println("子线程: 催催你")
			time.Sleep(time.Second)
		}
	}
}

func DemoChannelSelect() {
	quit_flag := make(chan string)
	urge := make(chan string)

	go channelSelect(urge, quit_flag)

	for index, _ := range [10]int{} {
		_ = <-urge
		fmt.Printf("被催了%d次\n", index+1)
	}
	fmt.Println("烦了 你给我死!")
	quit_flag <- "滚！"

	time.Sleep(1)

}
